#pragma once

class DPlayer;
class DIRenderer;
class DWorld;
class DIResourceManager;
class DInput;
class DLoaderThread;

class DBackground;

namespace GameStates
{
    class IState;
}

class DGame : public boost::enable_shared_from_this<DGame>
{
public:
    DGame(boost::shared_ptr<DIRenderer> renderer, boost::shared_ptr<DInput> input);
	~DGame(void);

	bool init();
	void update(float dt);
	void render();

    void changeState(boost::shared_ptr<GameStates::IState> newState);
    bool advanceWorld(bool& bLoading);

    boost::shared_ptr<DIRenderer> renderer() const;
    boost::shared_ptr<DIResourceManager> globalResourceManager() const;
    boost::shared_ptr<DInput> input() const;
    boost::shared_ptr<DPlayer> player() const;
	boost::shared_ptr<DWorld> world() const;
private:
    bool loadWorld(const std::string& worldPath, bool& bLoading);
    bool initGlobalResources();
    bool initGlobalGameObjects();

	boost::shared_ptr<DPlayer> m_player;
    boost::shared_ptr<DIRenderer> m_renderer;
	boost::shared_ptr<DInput> m_input;
    boost::shared_ptr<DIResourceManager> m_globalResourceManager;
	boost::shared_ptr<DBackground> m_back;

    boost::shared_ptr<DWorld> m_world;
    int m_nCurrentWorldIndex;
	boost::shared_ptr<DLoaderThread> m_loader;

    boost::weak_ptr<GameStates::IState> m_currentState;
};
